package Offer_24;

import org.w3c.dom.ls.LSInput;
import stackAndQueue.Stack;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/30 10:08
 */
public class Solution {
    static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
    //头插 进入一个新链表
    public ListNode reverseList(ListNode head) {
        ListNode left,right;
        left = head;
        right = null;
        while (left!=null){
            ListNode tem = left.next;
            left.next = right;
            right = left;
            left = tem;
        }
        return right;
    }
    //递归
    public ListNode reverseListD(ListNode head) {
        return reCall(head,null);

    }
    ListNode reCall(ListNode cur,ListNode pre){
        if (cur==null) {
            return pre;
        }
        ListNode res = reCall(cur.next,cur);
        cur.next = pre;
        return res;
    }

}
